package gang.org.springframework.framework.annotation;

import gang.org.springframework.framework.core.type.classreading.GangMetadataReader;
import gang.org.springframework.framework.io.GangResource;
import gang.org.springframework.framework.metadata.GangAnnotationMetadata;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @author gang.chen
 * @description 业务意义
 * 场景一
 *  项目启动，对主类SpringbootManualApplication的封装
 * 场景二
 *  项目启动，对自动装配类GangDispatcherServletAutoConfiguration等的封装
 * @Date 2021/6/23 8:30
 */
public class GangConfigurationClass
{
    private String beanName;

    private final GangResource resource;

    private final GangAnnotationMetadata metadata;

    private final Set<GangBeanMethod> beanMethods = new LinkedHashSet<>();

    private final Set<GangConfigurationClass> importedBy = new LinkedHashSet<>();

    /**
     * @param beanName bean name E.g springbootManualApplication
     * @param metadata {@link gang.org.springframework.framework.metadata.GangStandardAnnotationMetadata}
     * */
    public GangConfigurationClass(String beanName, GangAnnotationMetadata metadata) {
        this.beanName = beanName;
        this.metadata = metadata;
        this.resource = null;
    }

    //TODO
    public GangConfigurationClass(GangMetadataReader metadataReader, GangConfigurationClass importedBy){
        this.metadata = metadataReader.getAnnotationMetadata();
        this.resource = metadataReader.getResource();
        this.importedBy.add(importedBy);
    }


    public GangAnnotationMetadata getMetadata() {
        return this.metadata;
    }

    //TODO
    public boolean isImported(){
        return !this.importedBy.isEmpty();
    }

    public void setBeanName(String beanName) {
        this.beanName = beanName;
    }

    public void addBeanMethod(GangBeanMethod method){
        this.beanMethods.add(method);
    }
    public Set<GangBeanMethod> getBeanMethods() {
        return this.beanMethods;
    }

    public GangResource getResource() {
        return this.resource;
    }

    public String getBeanName() {
        return this.beanName;
    }
}
